
/*
'===============================================================================
'  HNG.Portal.BL.TblHinhAnhSanPhamManager
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace HNG.Portal.BLL
{
	public class TblHinhAnhSanPhamManager : TblHinhAnhSanPhamManagerBase
	{
        SqlConnection Conn = new SqlConnection(HNG.LIB.Common.Connection.strConn);
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblHinhAnhSanPhamManager()
		{
			// Nothing for now.
		}

        public DataTable be_selectToGridView(TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity)
        {
            System.Text.StringBuilder sbSql = new System.Text.StringBuilder();
            SqlParameter[] _SqlParameter = new SqlParameter[9];
            try
            {
                sbSql.Append("WITH tblTemp AS").Append("\n");
                sbSql.Append("(").Append("\n");
                sbSql.Append("SELECT ROW_NUMBER() OVER(ORDER BY ");
                sbSql.AppendFormat("ch.{0} ", string.IsNullOrEmpty(_TblHinhAnhSanPhamEntity.SortExpression) ? "[ID]" : _TblHinhAnhSanPhamEntity.SortExpression);
                sbSql.Append(string.IsNullOrEmpty(_TblHinhAnhSanPhamEntity.SortDirection) ? " DESC" : _TblHinhAnhSanPhamEntity.SortDirection);
                sbSql.Append(") AS RowNum,").Append("\n");
                sbSql.Append("  ch.[ID],").Append("\n");
                sbSql.Append("  ch.[IDSanPham],").Append("\n");
                sbSql.Append("  ch.[Image],").Append("\n");
                sbSql.Append("  ch.[MoTa],").Append("\n");
                sbSql.Append("  ch.[TrangThai]").Append("\n");
                sbSql.Append("  FROM").Append("\n");
                sbSql.Append("  tblHinhAnhSanPham ch").Append("\n");
                sbSql.Append("  WHERE").Append("\n");
                sbSql.Append("  1 = 1").Append("\n");

                if (!string.IsNullOrEmpty(_TblHinhAnhSanPhamEntity.strIDSanPham))
                {
                    _SqlParameter[0] = new SqlParameter("@strIDSanPham", _TblHinhAnhSanPhamEntity.strIDSanPham);
                    sbSql.Append("  AND ch.[IDSanPham] LIKE @strIDSanPham").Append("\n");
                }

                sbSql.Append(")").Append("\n");
                sbSql.Append("SELECT *, (SELECT Max(RowNum) FROM tblTemp) TotalItems FROM tblTemp").Append("\n");
                sbSql.AppendFormat("WHERE RowNum BETWEEN {0} AND {1}", _TblHinhAnhSanPhamEntity.StartIndex, _TblHinhAnhSanPhamEntity.EndIndex).Append("\n");
            }
            catch { }
            return AE.SqlHelper.ExecuteDataTable(Conn, CommandType.Text, sbSql.ToString(), _SqlParameter);
        }
	}
}
